// @algorithm @lc id=2006 lang=cpp 
// @title find-the-student-that-will-replace-the-chalk


// @test([5,1,5],22)=0
// @test([3,4,1,2],25)=1
class Solution {
public:
    int chalkReplacer(vector<int>& chalk, int k) {
        for(int i=0; i<chalk.size(); i++){
            if(i) chalk[i] += chalk[i-1];
            if(k < chalk[i]) return i;
        }
        k %= chalk.back();
        return upper_bound(chalk.begin(), chalk.end(), k) - chalk.begin();
    }
};